/*
 *  Copyright (C) 2011 JiangHongTiao <jjurco.sk_gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package sk.lieskove.jianghongtiao.sitesearch.plugin;

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.sparql.vocabulary.FOAF;
import com.hp.hpl.jena.vocabulary.RDF;

import java.io.File;

/**
 *
 * @author JiangHongTiao <jjurco.sk_gmail.com>
 */
public class FoafTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Model m = ModelFactory.createDefaultModel();
        Resource me = m.createResource(
                "http://richard.cyganiak.de/foaf.rdf#cygri");
        me.addProperty(RDF.type, FOAF.Person);
        me.addProperty(FOAF.name, "Richard Cyganiak");
        me.addProperty(FOAF.birthday, "5.6.1987");
        me.addProperty(FOAF.currentProject, "Paris");
        me.addProperty(FOAF.gender, "male");
        me.addLiteral(FOAF.dnaChecksum, FOAF.dnaChecksum);

        File file1 = new File("/home/xjuraj/item1.txt");
        Resource page1 = m.createResource(file1.toURI().toASCIIString());
        page1.addLiteral(RDF.type, FOAF.Document);
        File file2 = new File("/home/xjuraj/item2.txt");
        Resource page2 = m.createResource(file2.toURI().toASCIIString());
        page2.addLiteral(RDF.type, FOAF.Document);
        File file3 = new File("/home/xjuraj/item3.txt");
        Resource page3 = m.createResource(file3.toURI().toASCIIString());
        page3.addLiteral(RDF.type, FOAF.Document);
        
        

        me.addProperty(FOAF.page, page1);
        me.addProperty(FOAF.page, page2);
        me.addProperty(FOAF.page, page3);

        Resource dan = m.createResource();
        dan.addProperty(RDF.type, FOAF.Person);
        dan.addProperty(FOAF.name, "Dan Brickley");
        me.addProperty(FOAF.knows, dan);

        Resource you = m.createResource("http://cyganiak.de/foaf.rdf");
        you.addProperty(FOAF.birthday, "5.6.1987");
        you.addProperty(FOAF.currentProject, "Paris");
        you.addProperty(FOAF.gender, "male");
        you.addProperty(FOAF.knows, dan);

        m.write(System.out, "RDF/XML");
        Selector s = new SimpleSelector(null, FOAF.page, (RDFNode) null);
        StmtIterator iter = m.listStatements(s);
        
//        System.out.println("Me id: " + me.);
//        System.out.println("You id: " + you.asNode().getBlankNodeId().toString());
//        System.out.println("Dan id: " + dan.asNode().getBlankNodeId().toString());

        while (iter.hasNext()) {
            System.out.println("--->" + iter.nextStatement().getResource().getURI());
        }
    }
}
